<script>
$(document).ready(function () {
	$('#grouped_menu > li > a').click(function(e){
		if ($(this).attr('class') != 'active'){
			$('#grouped_menu li ul').slideUp();// Collapse all menus' uls
			$(this).next().slideToggle();// Expand the corresponding ul
			$('#grouped_menu li a').removeClass('active');
			$(this).addClass('active');
		} else {
			$(this).next().slideToggle();// Collapse the corresponding ul
		}
		e.preventDefault();
	});
});
</script>
<ul id="grouped_menu">
	<?php
	foreach($module_group_list as $module_group){
		if(empty($_SESSION['user_is_root']) && $module_group['id']==1){
			continue;
		}
		$menu_list = $module_group['menu_list'];
	?>
	<li id="group_menu_<?=$module_group['id']?>"><a href="#"><span class="menu_items"><?=$module_group['name']?></span></a>
		<?php
		if(!empty($menu_list)){
		?>
		<ul>
			<?php
			foreach($menu_list as $menu){
				if(admin_check_permission($menu['id'],'r')){
					$class = '';
					if($module==$menu['name_function']){
						$class = 'class="menu_active"';
						$active_group_menu_id = $menu['parent_id'];
					}
			?>
				<li><a <?=$class?> href="<?=PATH_URL.'admincp/'.$menu['name_function'].'/'?>"><span class="menu_items"><?=$menu['name']?></span></a></li>
			<?php
				}
			}
			?>
		</ul>
		<?php
		}
		?>
	</li>
	<?php
	}
	?>
</ul>
<?php
if(!empty($active_group_menu_id)){
?>
<script>
var li_jele = $('#grouped_menu li#<?='group_menu_'.$active_group_menu_id?>');
li_jele.find('> a').addClass('active');
li_jele.find('> ul').slideToggle();// Expand the corresponding ul
</script>
<?php
}
?>